<template>
  <div id="text-book-select">
    <div
      class="wrapper-container"
      style="display: flex; flex-direction: column; width: 100%"
    >
      <div class="search-container">
        <div class="search-container-left">
          <div class="search-container-item">
            <span>教材编号:</span>
            <el-input
              style="width:120px"
              v-model="bh"
              size="mini"
              placeholder="请输入内容"
            ></el-input>
          </div>

          <div class="search-container-item">
            <span>教材名称:</span>
            <el-input
              style="width:120px"
              v-model="jcmc"
              size="mini"
              placeholder="请输入内容"
            ></el-input>
          </div>

          <div class="search-container-item">
            <span>作者:</span>
            <el-input
              style="width:120px"
              v-model="zz"
              size="mini"
              placeholder="请输入内容"
            ></el-input>
          </div>

          <div class="search-container-item">
            <span>出版社:</span>
            <el-input
              style="width:120px"
              v-model="cbs"
              size="mini"
              placeholder="请输入内容"
            ></el-input>
          </div>
          <div class="search-container-item">
            <span>出版日期:</span>

            <el-date-picker
              @change="handleSelectDate"
              size="mini"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              style="width:120px"
              v-model="cbrq"
              type="date"
              placeholder="选择日期"
              prefix-icon="aaa"
            >
            </el-date-picker>

          </div>

          <div class="search-button" style="margin-left: 20px" @click="getList">
            <img src="../../../../../assets/assessment/icon-search.png" alt="" />
            <span>查询</span>
          </div>
        </div>
      </div>
    </div>
    <div class="assessment-container">
      <div class="table-container">
        <el-table
          :data="tableData"
          border
          class="table-data"
          row-class-name="row-class"
          cell-class-name="cell-class"
          header-row-class-name="header-row-class"
          header-cell-class-name="header-cell-class"
          style="height: calc(100vh - 420px); overflow-y: auto"
          @selection-change="handleSelectionChange"
        >
        <el-table-column
            type="selection"
            label="操作"
            width="80"
            align="center"
        >
        </el-table-column>
          <el-table-column
            label="教材名称"
            prop="jcmc"
            align="center"
            width="120px"
          >
          </el-table-column>
          <el-table-column prop="bh" label="教材编号" align="center">
          </el-table-column>
          <el-table-column prop="cbs" label="出版社" align="center">
          </el-table-column>
          <el-table-column prop="cbrq" label="出版日期" align="center">
          </el-table-column>
          <el-table-column prop="zz" label="编者" align="center">
          </el-table-column>
          <el-table-column prop="createtime" label="入库时间" align="center">
          </el-table-column>
          <el-table-column prop="updatetime" label="修改时间" align="center">
          </el-table-column>
          <el-table-column prop="bz" label="备注" align="center">
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="bottom-block" style="display: block">
      <div class="text">
        当前共找到{{ total }}条记录,当前显示{{ startPage }}-{{ endPage }}条
      </div>
    </div>
    <div class="pagination-block">
      <el-pagination
        prev-text="上一页"
        next-text="下一页"
        :page-size="pageSize"
        layout="prev, pager, next, jumper"
        :total="total"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
      >
      </el-pagination>
    </div>
    <div class="search-container btn-caozuo">
      <el-button size="mini" type="warning" plain @click="submitBook">确定</el-button>
      <el-button size="mini" type="danger" plain @click="cancelBook">取消</el-button>
    </div>
  </div>
</template>

<script>
import ButtonItem from "@/components/ButtonItem.vue";
import {text_book_list} from  "@/api/trainingManagement/place.js";
export default {
  components: {
    ButtonItem,
  },
  data() {
    return {
      total: 0, //总条数
      pageSize: 50, //条数
      startPage: 0, //开始条数
      endPage: 0, //结束条数
      currentPage: 1, //当前页数
      selectList: [],
      bh: '', // 教材编号
      jcmc: '', // 教材名称
      zz: '', // 作者
      cbs: '', // 出版社
      cbrq: '', // 出版日期
      tableData: [],
      selectBookList: [],
      selectId: "",
      selectName: "",

      id: "",
      grade: "",
      professional: "",
      className: "",
      classHours: "",
      system: "",
      teachingOffice: "",
      purchase: "",
    };
  },
  created() {
    this.getList()
  },
  mounted() {
    this.id = this.$route.query.id;
    this.grade = this.$route.query.grade;
    this.professional = this.$route.query.professional;
    this.className = this.$route.query.className;
    this.classHours = this.$route.query.classHours;
    this.system = this.$route.query.system;
    this.teachingOffice = this.$route.query.teachingOffice;
    this.purchase = this.$route.query.purchase; //出版年月
  },
  methods: {
    handleSelectDate(val){
      if(val == ''){
        this.cbrq = ''
      }
    },
    getList(){
      var bh = this.bh;
      var jcmc = this.jcmc;
      var zz = this.zz;
      var cbs = this.cbs;
      var cbrq = this.cbrq;
      var current = this.currentPage;
      var size = this.pageSize;
      text_book_list(bh, jcmc, zz, cbs, cbrq,current, size).then(res=>{
        if(res.data.code == 200){
          this.tableData = res.data.data.records;
          this.total = res.data.data.total;
          var length = this.tableData.length;
          this.calculatePage(this.pageSize, res.data.data.current, length);
        }
      })
    },
    // 计算开始和结束条数
    calculatePage(pageSize, current, length) {
      if (current == 1) {
        if (length != 0) {
          this.startPage = 1;
          this.endPage = length;
        }
      } else {
        this.startPage = pageSize * (current - 1) + 1;
        this.endPage = parseInt(this.startPage) + parseInt(length) - 1;
      }
    },
    // 取消选择
    cancelBook() {
      this.$router.push({
        path: "/admin/teachingTaskManage/teachingclass/addTextbook",
        query: {
          id:this.id,
          grade: this.grade,
          professional: this.professional,
          className: this.className,
          classHours: this.classHours,
          system: this.system,
          teachingOffice: this.teachingOffice,
        }
      });
    },
      submitBook() {
        if (this.selectBookList.length > 0) {
          var ids = "";
          var names = "";
          var cbs = "";
          var cbrq = "";
          var bz = "";
          // if (this.selectBookList.length > 1) {
          //   this.$message.warning("最多选择一本教材！");
          //   return;
          // }

          this.selectBookList.forEach(item => {
            // ids.push(item.textbookInfo.id);
            // names.push(item.textbookInfo.cbs);
            // cbs.push(item.textbookInfo.cbs);
            // cbrq.push(item.textbookInfo.cbrq);
            // bz.push(item.textbookInfo.bz)
            ids = item.id;
            names = item.jcmc;
            cbs = item.cbs;
            cbrq = item.cbrq;
            bz = item.zz;
          })
          // this.selectId = ids.join(",")
          // this.selectName = names.join(",")
          localStorage.setItem('jcid', ids)
          localStorage.setItem('jcmc', names)
          localStorage.setItem('bz',bz)
          localStorage.setItem('cbs',cbs)
          localStorage.setItem('cbrq',cbrq)
          this.$router.push({
            path: "/admin/teachingTaskManage/teachingclass/addTextbook",
            query: {
              selectId: ids,
              selectName: names,
              cbs: cbs,
              cbrq: cbrq,
              bz:bz,
              cbs:cbs,
              id:this.id,
              grade: this.grade,
              professional: this.professional,
              className: this.className,
              classHours: this.classHours,
              system: this.system,
              teachingOffice: this.teachingOffice,
              purchase: this.purchase
            }
          });
        } else {
          this.$message.warning("请先选择教材信息!");
          return
        }
      },
      handleSelectionChange(val) {
          this.selectBookList = val;
      },
  },
  computed: {}, //计算属性
};
</script>
<style lang="less" scoped>
.assessment-container {
  .el-dialog__body {
    height: 251px;
  }
  .el-dialog__footer {
    padding: 10px 20px 45px;
  }
  .el-checkbox__inner:hover {
    border-color: #004ca7;
  }
  .el-checkbox__inner {
    border: 1px solid #004ca7;
    border-radius: 0;
    height: 18px;
    width: 18px;
  }
  .el-checkbox__inner::after {
    height: 10px;
    left: 6px;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #004ca7;
    border-color: #004ca7;
  }
  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #004ca7;
  }
  .el-checkbox.is-bordered.is-checked {
    border-color: #004ca7;
  }
  .el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #004ca7;
  }
}
</style>
<style lang="less" scoped>
@import "../../../../../styles/text.less";
/deep/ .szjky .el-dialog__body {
  height: 432px;
}
.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
</style>
<style lang="less" scoped>
@import "../../../../../styles/supervision.less";

@import "../../../../../styles/text.less";
// 表格底部样式
@import "../../../../../styles/delayedExam.less";

.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

.wrapper-container {
  width: 1711px;
  margin: 0 auto;
}

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  width: 100%;
  flex-wrap: wrap;
  .search-container-item {
    width: 12%;
    margin-right: 0px;
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      margin-bottom: 20px;
      align-items: center;
      /deep/ .el-input__inner {
          height: 28px;
      }
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}
.bottom-block {
  // display: flex;
  flex-direction: row;
  justify-content: space-between !important;
  .export-button {
    width: 127px;
    height: 27px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      margin-left: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
  }
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}

.search-button {
  width: 77px;
  height: 28px;
  line-height: 28px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  > span {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }
  > img {
    width: 20px;
    height: 20px;
    margin-right: 4px;
  }
}

.mar-lef-2 {
  margin-left: 20px;
}
.undeLine {
  text-decoration: underline;
  cursor: pointer;
}
.btn-caozuo {
  display: flex;
    align-items: center;
    justify-content: space-around;
    width: 500px;
    margin: 40px auto;
}

.assessment-container {
  width: calc(100% - 20px);
  .table-container {
     width: 100%;
  }
}
</style>

<style lang="less" scoped>
  #text-book-select{
    /deep/ .el-button--warning.is-plain{
      background: #FFF6EF;
      border-color: #F3B815;
      color: #F3B815;
      border-radius: 6px;
    }
    /deep/ .el-button--warning.is-plain:focus, .el-button--warning.is-plain:hover{
      color: #F3B815;
      background: #FFF6EF;
      border: 1px solid #F3B815;
      border-radius: 6px;
    }

    /deep/ .el-button--success.is-plain{
      background: #F1FFF8;
      border-color: #02C86C;
      color: #02C86C;
      border-radius: 6px;
    }
    /deep/ .el-button--success.is-plain:hover{
      background: #F1FFF8;
      border: 1px solid #02C86C;
      color: #02C86C;
      border-radius: 6px;
    }

    /deep/ .el-button--info.is-plain{
      background: #EBE6FF;
      border-color: #5230E9;
      color: #5230E9;
      border-radius: 6px;
    }

    /deep/ .el-button--info.is-plain:hover{
      background: #EBE6FF;
      border: 1px solid #5230E9;
      color: #5230E9;
      border-radius: 6px;
    }

    /deep/ .el-button--danger.is-plain{
      background: #FFEFEF;
      border-color: #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }

    /deep/ .el-button--danger.is-plain:hover{
      background: #FFEFEF;
      border: 1px solid #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }
  }
</style>
